﻿{include file="public/header"}
<title>订单录入</title>
</head>
<body>


<article class="page-container">
<form>
    <div class="ch-row ch-info-form">
        <div class="flex1">标题：</div>
        <div class="flex2">
            <input type="text" class="form-control fid" value="{$data.title}" name="title"  placeholder="请输入标题">
        </div>
    </div>
    
    <?php if($data['fen']==0){ ?>
    <div class="ch-row ch-info-form">
        <div class="flex1">分类：</div>
        <div class="flex2">
            <select style="padding: 0.4% ;display: inline-block" class="form-control" name="type">
                <option selected="selected" value="{$data['type']}">{$data['pro_ids']}</option>
                {volist name='go' id='v'}
                <option value="{$v.tool_id}">{$v.content}</option>
                {/volist}
            </select>
        </div>
    </div>
    <?php } ?>
    <input type="hidden"  value="{$data['fen']}" name="fen"  >
    <?php if($data['fen']==1){ ?>
    <div class="ch-row ch-info-form">
        <div class="flex1">链接地址：</div>
        <div class="flex2">
            <input type="text" class="form-control" value="{$data['url']}" name="url"  placeholder="请输入标题">
        </div>
    </div>
    <?php } ?>
    <div class="ch-row ch-info-form">
        <div class="flex1">图片：</div>
        <div class="flex2">
            <div id="uploader-demo">
                    <!--用来存放item-->
                <div id="fileList" class="uploader-list">
                    <div id="" class="file-item thumbnail">
                        <div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>
                        <img style="width: 100px;height: 100px;" src="{$data['logo']}">
                        <input name="logo" type="hidden" value="{$data['logo']}">
                        <div class="info"></div>
                    </div>

                </div>
                <div id="filePicker">选择图片</div>
            </div>
        </div>
    </div>
    <div class="ch-row ch-info-form">
        <div class="flex1">备注：</div>
        <div class="flex2">
            <textarea placeholder="请输入备注" name="rmake">{$data['rmake']}</textarea>
        </div>
    </div>
    <input type="hidden"  value="{$data.article_id}" name="article_id"  >
    <div class="ch-row">
        <div class="flex1">
            <button class="btn btn-primary radius" style="width: 100%;" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
        </div>
    </div>
</form>

</article>
{include file="public/footer"}
<script>
    var E = window.wangEditor;
    var editor2  = new E('#editor');
    editor2.customConfig.uploadImgServer =  "{:Url('index/upload/upload_file')}";
    editor2.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
    editor2.customConfig.uploadImgMaxLength = 5;
    editor2.customConfig.uploadFileName = 'file';
    editor2.customConfig.uploadImgHeaders = {
        'Accept' : 'multipart/form-data'
    };
    editor2.customConfig.uploadImgHooks = {
        error: function (xhr, editor) {
            alert("2:"+xhr);

        },
        fail: function (xhr, editor, result) {
            alert("1:"+xhr);
        },
        success:function(xhr, editor, result){

        },
        customInsert: function (insertImg, result, editor) {
            insertImg(result.data)
        }
    };
    editor2.create();
    editor2.txt.html();
    $('.radius').click(function () {

        var src = "{:Url('index/article/edit')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data:$('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                        parent.location.reload()
                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });



    });
    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object){
        $(object).parent().remove();
        count-=1;
    }
    var count=0;
    $(function(){
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate:true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });
        uploader.on( 'beforeFileQueued', function( file ) {
            if(count>0){
                alert('只能添加一张头像');
                return false;
            }
            return true;
        });
        uploader.option( 'compress', {

            width: 750,
            height: 9808,
// 图片质量，只有type为`image/jpeg`的时候才有效。
            quality: 90,

// 是否允许放大，如果想要生成小图的时候不失真，此选项应该设置为false.
            allowMagnify: false,

// 是否允许裁剪。
            crop: false,

// 是否保留头部meta信息。
            preserveHeaders: true,

// 如果发现压缩后文件大小比原来还大，则使用原来图片
// 此属性可能会影响图片自动纠正功能
            noCompressIfLarger: false,

// 单位字节，如果图片大小小于此值，不会采用压缩。
            compressSize: 0
        });
        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>'+
                '<img style="width: 100px;height: 100px;">' +
                '<input name="logo" type="hidden" value="">'+
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
                $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, 100, 100 );
        });



        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
            }


            $percent.css( 'width', percentage * 100 + '%' );
        });
        var s=[];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,res ) {
            var data = JSON.parse(res._raw);
            if(data.errcode==300){
                layer.alert(data.msg);
            }
            var url = data.data;
            count+=1;
            $( '#'+file.id).find("logo").attr("src",url);
            $( '#'+file.id).find("input").val(url);
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });
</script>
</body>
</html>